#include <iostream>
#include <stdio.h>
#include <cassert>
#include <unistd.h>
#include <pthread.h>
using namespace std;

int num =0;

void* myfunc(void* args)
{
    while(true)
    {
        cout<<"我是新线程  "<<"num= "<<num++<<"  &num="<<&num<<endl;
        sleep(1);
    }

}

int main()
{
    pthread_t ptd;
    int n = pthread_create(&ptd, NULL, myfunc, (void*)"pthread one");  //创建一个新线程，将资源分配给他
    assert(n==0);  

    while(true)
    {
        char buffersize[64];
        snprintf(buffersize,64,"0x%x",ptd);
        cout<<"我是主线程 "<<" num= "<<num<<" &num="<<&num<<" ptd=   "<<ptd<<endl;
        sleep(1);
    }

    return 0;
}